<template>
<section class="top">
    <div class="wCen">
        <!-- left -->
        <div class="top_l" @click="switchNav">
            <img src="@/assets/img/icon_menu_wap.svg" class="menu" />
            <!-- <span class="top_l_txt">{{$t('menu')}}</span> -->
        </div>
        <!-- <div class="top_c">
            <a :href="localeCn?'/':'/en'"><img src="@/assets/img/logo.svg" alt="" class="top_c_logo"></a>
        </div> -->
        <div class="top_r">
            <img src="@/assets/img/icon_search_wap.svg" class="img hand img1" @click.stop="isShowSearch=true" />
            <img src="@/assets/img/icon_avatar_wap.svg" class="img hand img2" @click.stop="switchInfoBox" />
            <img :src="icon_en" class="img hand img3" @click.stop="go2En" v-if="localeCn" />
            <img :src="icon_cn" class="img hand img3" @click.stop="go2Cn" v-else />
        </div>
    </div>
    <!-- 用户登录弹框 -->
    <div v-if="showInfoBox" class="infoBox">
        <common-float-menu />
    </div>
    <!-- 搜索弹框 -->
    <div class="searchModal" v-show="isShowSearch">
        <div class="mask" @click="isShowSearch=false"></div>
        <img src="@/assets/img/icon_close_white.svg" class="close" @click.stop="isShowSearch=false" />
        <div class="searchBox">
            <el-input v-model="keyword" :placeholder="$t('placeholder-search')" class="inp" v-show="isShowSearch" clearable maxlength="50" minlength="1"></el-input>
            <img src="@/assets/img/icon_search.svg" class="searchBtn" @click.stop="search" />
        </div>
    </div>
</section>
</template>

<script>
import util from "@/libs/util.js";
export default {
    data() {
        return {
            isShowSearch: false,
            keyword: '',
            icon_en: require('@/assets/img/icon_en_wap.svg'),
            icon_cn: require('@/assets/img/icon_cn_wap.svg')
        }
    },
    computed: {
        // 导航的显示与隐藏
        showNavs() {
            return this.$store.state.data.showNavs
        },
        // 用户信息 登录注册的显示与隐藏
        showInfoBox() {
            return this.$store.state.data.showInfoBox
        },
    },
    mounted() {

    },
    methods: {
        // 搜索
        search() {
            if (!this.keyword) {
                this.$message({
                    message: this.$t('search-tip'),
                    type: 'error'
                });
                return
            }
            let routeUrl = this.$router.resolve({
                path: this.localeCn ? `/search` : '/en/search',
                query: {
                    keyword: this.keyword
                }
            })
            window.open(routeUrl.href, '_blank')
        },
        // 由于点击遮罩层也需要隐藏菜单，所以这样写
        switchNav() {
            this.$store.commit('submitShowNavs', !this.showNavs)
        },
        // 控制用户信息弹框的显示与隐藏
        switchInfoBox() {
            this.$store.commit('submitShowInfoBox', !this.showInfoBox)
        },

        pageChange(path) {
            util.pageChange(this.$router, path)
        },
    },
}
</script>

<style lang="scss" scoped>
$baseBlue: #191E33;

.topRight__box {
    max-width: 80px;
}

.top {
    height: 50px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(37, 53, 84, 0.2);

    .wCen {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0 15px;

        .top_l {
            color: $baseBlue;
            display: flex;
            align-items: center;

            .menu {
                width: 26px;
            }

            &_txt {
                font-size: 14px;
                margin-left: 4px;
            }
        }

        .top_c {
            &_logo {
                display: flex;
                align-items: center;
                width: 60px;
            }
        }

        .top_r {
            display: flex;
            align-items: center;

            .img {
                width: 30px;

                &:not(:last-child) {
                    margin-right: 15px;
                }

                &1 {
                    width: 28px;
                    padding-top: 1px;
                }

                &3 {
                    width: 20px;
                }
            }
        }

        .ml_2 {
            margin-left: 20px;
        }
    }

    // 用户信息弹框
    .infoBox {}
}

.searchModal {
    right: 0;
    top: 0;
    position: fixed;
    z-index: 99;
    display: flex;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    padding-top: 30%;
    box-sizing: border-box;
    .mask{
        background-color: rgba(0, 0, 0, 0.7);
        height: 100vh;
        width: 100vw;
        right: 0;
        top: 0;
        position: fixed;
    }

    .close {
        position: absolute;
        width: 20px;
        cursor: pointer;
        top: 20px;
        right: 20px;
    }

    .searchBox {
        box-sizing: border-box;
        padding: 0 30px;
        display: flex;
        align-items: center;
        width: 100%;
        height: 100px;
        position: relative;

        :deep(.el-input__inner) {
            color: #191E33;
            height: 40px;
            font-size: 16px;
            border: none;
            padding-left: 40px;
            padding-right: 40px;
        }

        // 搜索按钮
        .searchBtn {
            width: 20px;
            cursor: pointer;
            position: absolute;
            left: 40px;
        }
    }

}
</style>
<style lang="scss" scoped>
@media (min-width:768px) and (max-width:999px) {
    .searchModal {
        padding-top: 10%;
    }
}
</style>
